<?php
/**
*  Project Name:  NET114.COM
*  @package :  class.main
*  @classID :  Func.class.php
*  @author  :  邝达峰
*  @date    :  2014-03-18
*  公用函数类
*/

class Func
{
	/**
	 *  subStr中文截取
	 * @param  $string 需要截取的字符
	 * @param  $sublen 截取长度
	 * @param  $suffix 截取后缀
	 * @param  $start 截取开始
	 * @author  邝达峰
	 * @return string
	 */
	public static function cnSubStr($string,$sublen,$suffix='...',$start=0)
	{
		if($sublen>=strlen($string))
		{
			return $string;
		}
		$i = 0;
		while($i<$start){
			if(ord($string[$i])>127){
				$i = $i+2;
			}else{
				$i++;
			}
		}
		$start = $i;
		if($sublen==''){
			return substr($string,$start);
		}
		elseif($sublen>0){
			$end = $start+$sublen;
			while($i<$end) {
				if(ord($string[$i])>127){
					$i = $i+2;
				}else{
					$i++;
				}
			}
			$end = $i;
			$length = $end-$start;
			return substr($string,$start,$length) . $suffix;
		}elseif($sublen==0){
			return;
		}
	}


	/**
	 * 程序功能：截取全角和半角（汉字和英文）混合的字符串以避免乱码
	 * @param   $str_cut    需要截断的字符串
	 * @param  $length     允许字符串显示的最大长度
	 * @return string
	 */
	public static  function substr_cut($str_cut,$length)
	{
		if (strlen($str_cut) > $length)
		{
			for($i=0; $i < $length; $i++)
				if (ord($str_cut[$i]) > 128)    $i++;
			$str_cut = substr($str_cut,0,$i)."..";
		}
		return $str_cut;
	}




	/**
	 * 过滤特殊字符
	 * @param  $str 需要过滤的字符
	 * @author  邝达峰
	 * @return string
	 */
	public static function filterChar($str='') {
		$arr = array ('"' => '', "'" => '', '%' => '', '?' => '', "\\" => '', '~' => '', '`' => '', '!' => '', '@' => '', '#' => '', '$' => '', '%' => '', '^' => '', '&' => '', '*' => '', '<' => '', '>' => '', ':' => '', ';' => '', '+' => '', '=' => '', '/' => '', ',' => '' );
		return trim(strtr($str,$arr));
	}

	/**
	 * 过滤引号
	 * @param  $str 需要过滤的字符
	 * @author  邝达峰
	 * @return string
	 */
	public static function filterQuotes($str='') {
		$arr = array ('"' => '', "'" => '');
		return trim(strtr($str,$arr));
	}

	/**
	 * 小写数字改中午大写数字
	 * @param  $num 需要转换的数字
	 * @author  邝达峰
	 * @return string
	 */
	public static function numerUpper($num='') {
		$arr = array (1 => '一', 2 => '二', 3 => '三', 4 => '四', 5 => '五', 6 => '六', 7 => '七', 8 => '八', 9 => '九' );
		return trim(strtr($num,$arr));
	}

	/**
	 * 判断字符是否邮箱格式
	 * @param $str 需要处理的字符
	 * @author 邝达峰
	 * @return boolen
	 */
	public static function matchEmailFormat($str='') {
		if(!empty($str)){
			$match = '/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/';
			$check = preg_match($match, $str);
			return $check;
		}
	}


	/**
	 * 判断字符是否手机格式
	 * @param $str 需要处理的字符
	 * @author 邝达峰
	 * @return boolen
	 */
	public static function matchMobileFormat($str='') {
		if(!empty($str) && is_numeric($str) && strlen($str)==11){
			$match = "/1[123456789]{1}\d{9}$/";
			$check = preg_match($match, $str);
			return $check;
		}
	}



	/**
	 * 清除字符中的空白与回车
	 * @param $str 需要处理的字符
	 * @author 邝达峰
	 * @return string
	 */
	public static function clearSpacEnter($str='') {
		if(!empty($str)){
			$str = trim($str);
			$search=array(" ","　","\t","\n","\r");
			$replace =array("","","","","");
			return str_replace($search,$replace,$str);
		}
	}

	/**
	 * 把数组转换成stdClass对象
	 * @param $array 需要转换的数组
	 * @author 邝达峰
	 * @return object
	 */
	public static function arrayToObject($array='') {
		if(!empty($array)){
			$object = new stdClass();
			if(is_array($array) && count($array) > 0){
				foreach($array as $name=>$value){
					$name = strtolower(trim($name));
					if($name) {
						$object->$name = $value;
					}
				}
				return $object;
			}
		}
		return false;
	}


	/**
	 * 把stdClass转换成数组
	 * @param object 需要转换的对象
	 * @author 邝达峰
	 * @return array
	 */
	public static function objectToArray($object='') {
		if(!empty($object)){
			if(is_object($object)){
				$array = get_object_vars($object);
				foreach ($array as $key => $val){
					$val = (is_array($val) || is_object($val)) ? self::object_to_array($val) : $val;
					$arrInfo[$key] = $val;
				}
				return $arrInfo;
			}
		}
		return false;
	}

	/**
	 * 输出页面样式
	 * @param $ver 版本号
	 * @param $path
	 * @author  邝达峰
	 * @return string
	 */
	public static function ouputCss($path = '' ,$ver = '')
	{
		if(!empty($path)){
			$strOutPath = '';
			if(is_string($path)){
				$arrPath = explode(',',$path);
				if(is_array($arrPath)){
					$strFile = '';
					$strVer = !empty($ver)?'/'.$ver.'/':'/';
					$intCount = count($arrPath);
					if($intCount > 1){
						foreach ($arrPath as $v){
							$arrFilePath = explode('/',$v);
							$strPopFile = array_pop($arrFilePath);
							$strTrukPath = implode('/',$arrFilePath);
							if(is_numeric($arrFilePath[count($arrFilePath)-1])){
								$strFile = $strFile.$strTrukPath.'/'.str_replace('.css','',$strPopFile).',';
							}else {
								$strFile = $strFile.$strTrukPath.$strVer.str_replace('.css','',$strPopFile).',';
							}
						}
						$strOutPath = USER_THEME_CSS_URL.'utilities/yui.css.php?f='.trim($strFile,',');
					}else
					{
						$arrFilePath = explode('/',$path);
						$strPopFile = array_pop($arrFilePath);
						$strTrukPath = implode('/',$arrFilePath);
						if(is_numeric($arrFilePath[count($arrFilePath)-1])){
							$strVer ='/';
						}
						$strFile = $strFile.$strTrukPath.$strVer.$strPopFile;
						$strOutPath = USER_THEME_CSS_URL.trim($strFile,'/');
					}
				}
			}
			return $strOutPath;
		}
	}


	/**
	 * 输出页面样式
	 * @param $ver 版本号
	 * @param $path
	 * @author  邝达峰
	 * @return string
	 */
	public static function ouputJS($path = '' ,$ver = '')
	{
		if(!empty($path)){
			$strOutPath = '';
			if(is_string($path)){
				$arrPath = explode(',',$path);
				if(is_array($arrPath)){
					$strFile = '';
					$strVer = !empty($ver)?'/'.$ver.'/':'/';
					$intCount = count($arrPath);
					if($intCount > 1){
						foreach ($arrPath as $v){
							$arrFilePath = explode('/',$v);
							$strPopFile = array_pop($arrFilePath);
							$strTrukPath = implode('/',$arrFilePath);
							if(is_numeric($arrFilePath[count($arrFilePath)-1])){
								$strFile = $strFile.$strTrukPath.'/'.rtrim($strPopFile,'.js').',';
							}else {
								$strFile = $strFile.$strTrukPath.$strVer.rtrim($strPopFile,'.js').',';
							}
						}
						$strOutPath = USER_THEME_JS_URL.'utilities/yui.js.php?f='.trim($strFile,',');
					}else
					{
						$arrFilePath = explode('/',$path);
						$strPopFile = array_pop($arrFilePath);
						$strTrukPath = implode('/',$arrFilePath);
						if(is_numeric($arrFilePath[count($arrFilePath)-1])){
							$strVer ='/';
						}
						$strFile = $strFile.$strTrukPath.$strVer.$strPopFile;
						$strOutPath = USER_THEME_JS_URL.trim($strFile,'/');
					}
				}
			}
			return $strOutPath;
		}
	}


	/**
	 * 上传文件地址处理 文件路径集群处理
	 * @author 邝达峰
     * @param array $url 
     */
	public static function fileUrlHandle($url='')
	{
		if(!empty($url)){
			#文件路径处理
			$file_pathes = explode('|',USER_THEME_FILE_URL);
			#过滤处理域名
			foreach ($file_pathes as $k){
				$url = str_replace($k,'',$url);
			}
			#读取文件配置
			$arrFileConfig = Config::get('file');
			#文件路径处理
			$arrFilePath = pathinfo($url);
			$fileName = $arrFilePath['basename'];
			$arrconfig = $arrFileConfig['FILE_DOMAIN_CFG']['FILE_CONFIG'];
			$sttDomain = $arrconfig['default']['domain'][0];
			$arrStr = explode('.',$fileName);
			$strPrefix = $arrStr[0];
			$arrPrefix = explode('_',$strPrefix);
			if(!empty($arrPrefix) && count($arrPrefix) == 2){
				$strPrefix = substr($arrPrefix[0],0,1);
				if(is_array($arrconfig[$strPrefix])){
					if(in_array($arrPrefix[0],$arrconfig[$strPrefix]['prefix'])){
						$sttDomain= $arrconfig[$strPrefix]['domain'][0];
					}
				}
			}
		}
		$url = $sttDomain.str_replace($sttDomain,'',$url);
		return $url;
	}


	/**
	 * 图片路径集群处理
	 * @author 邝达峰
	 * @param array $src 图片地址
	 * @param string $type 图片的类型  默认大图 b 大图 m 中图 s小图 ,z自定义
	 * @param string $watermark 是否打水印 1 不打水印 0 打水印 默认不打水印
	 */
	public static function imageSrcHandle($src='',$type='',$size='',$watermark = '')
	{
		if(!empty($src))
		{
			#图片服务器处理
			$dynamic_img_pathes = explode('|',USER_THEME_DYNAMIC_IMAGE_GOTO_SEVER);#动态图片保存目录
			$static_img_pathes = explode('|',USER_THEME_STATIC_IMAGE_GOTO_SEVER);#静态图片保存目录
			$dynamic_img_server = explode('|',USER_THEME_DYNAMIC_URL);#动态服务器地址
			$static_img_server = explode('|',USER_THEME_STATIC_URL);#静态服务器地址
			$img_pathes = explode('|',USER_THEME_IMAGE_URL);
			#过滤处理域名
			foreach ($img_pathes as $k){
				$src = str_replace($k,'',$src);
			}
			#图片服务器路径[随机]
			$img_path = $img_pathes[array_rand($img_pathes)];
			$dynamic_img_path = $dynamic_img_server[array_rand($dynamic_img_server)];#动态
			$static_img_path = $static_img_server[array_rand($static_img_server)];#静态
			#图片服务器处理
			$arrImagePath = explode('/',trim(str_replace('..','',$src),'/'));
			$arrImageBasePath = pathinfo($src);
			$strBasename = $arrImageBasePath['basename'];
			if(empty($arrImageBasePath['filename']))
			{
				return false;
			}
			#处理图片路径
			if(is_array($arrImagePath) && count($arrImagePath) > 0){
				#获取到文件配置
				$arrFileConfig = Config::get('file');
				$strImagePath = $arrImagePath[0];
				if(in_array($strImagePath,$dynamic_img_pathes)){
					#图片路径
					$strImageHost = $dynamic_img_path;
					#处理动态图片域名
					$arrconfig = $arrFileConfig['FILE_DOMAIN_CFG']['IMG_CONFIG'];
					$arrStr = explode('.',$strBasename);
					$strPrefix = $arrStr[0];
					$arrPrefix = explode('_',$strPrefix);
					if(count($arrPrefix) == 3){
						$arrPrefix = array_slice($arrPrefix,1);
					}
					if(!empty($arrPrefix) && count($arrPrefix) == 2){
						$strPrefix = substr($arrPrefix[0],0,1);
						if(is_array($arrconfig[$strPrefix])){
							if(in_array($arrPrefix[0],$arrconfig[$strPrefix]['prefix'])){
								$strImageHost= $arrconfig[$strPrefix]['domain'][0];
							}
						}
					}
					#end
				}else if(in_array($strImagePath,$static_img_pathes))
				{
					$strImageHost = $static_img_path;
					#如果是静态图片直接返回
					return $strImageHost.$src;
				}
			}else{
				$strImageHost = $dynamic_img_path;
			}
			#返回地址
			$resrc = $strImageHost.$src;
			#处理图片类型
			if(!empty($type)){
				$resrc = str_replace('/m_',"/",$resrc);
				$resrc = str_replace('/s_',"/",$resrc);
				$resrc = str_replace('/zf_',"/",$resrc);
			}
			#处理大图,中图,小图
			if (strpos($resrc,'-') !== false) {
				$resrc = substr($resrc,0,strpos($resrc,'-')).'.'.$arrImageBasePath['extension'];
			}
			if($type=='m'){
				$resrc = preg_replace('/([^\/]+)$/',"m_$1",$resrc);
			}else if($type=='s')
			{
				$resrc = preg_replace('/([^\/]+)$/',"s_$1",$resrc);
			}else if($type=='z' || $type=='zf')
			{
				//处理自定义图片
				if(!empty($size)){
					#图片原始大小
					$arrImageInfo = explode('_',$arrStr[1]);
					$strImageW = $arrImageInfo[1];
					$strImageH = $arrImageInfo[2];
		
					$arrSize = explode('*',$size);
					if(is_array($arrSize) && count($arrSize) > 0)
					{
						$wSize = $arrSize[0];
						$hSize = $arrSize[1];
					}
					
					if($wSize=='auto'){
						$wSize = $strImageW;
					}
					
					if($hSize=='auto'){
						$hSize = $strImageH;
					}
					
					if(!empty($wSize)){
						$strSizeUrl = '-'.$wSize;
					}
					if(!empty($hSize)){
						$strSizeUrl .= '-'.$hSize;
					}
					#是否打水印
					if(is_numeric($watermark) && $watermark==1){
						$strSizeUrl=$strSizeUrl.'-1';//不打水印
					}else if(is_numeric($watermark) && $watermark==0){
						$strSizeUrl=$strSizeUrl.'-0';//打水印
					}
					$arrSrc = pathinfo($src);
					#过滤掉自定义参数
					$strBasename = str_replace('m_',"",$strBasename);
					$strBasename = str_replace('s_',"",$strBasename);
					$strBasename = str_replace('zf_',"",$strBasename);
					#过滤掉自定义参数
					if (strpos($strBasename,'-') !== false) {
						$strBasename = substr($strBasename,0,strpos($strBasename,'-')).'.'.$arrSrc['extension'];
					}
					$strDirname = $arrSrc['dirname'];
					$arrSrcPath = explode('.',$strBasename);
					$strSizeImg = '';
					if(is_array($arrSrcPath)){
						$intSrcSum = count($arrSrcPath);
						foreach ($arrSrcPath as $k=>$v){
							if($intSrcSum==($k+1)){
								$strSizeImg = rtrim($strSizeImg,'.').rtrim($strSizeUrl.'.'.$v,'.');
							}else{
								$strSizeImg.= $v.'.';
							}
						}
					}
					//自定义补白
					if($type=='zf')
					{
						$resrc = $strImageHost.$strDirname.'/'.'zf_'.$strSizeImg;
					}else
					{
						$resrc = $strImageHost.$strDirname.'/'.$strSizeImg;
					}
				}
			}
			return $resrc;
		}else
		{
			return false;
		}
	}


	/**
	 * 从字符串编码转换
	 * @param $string 需要转换的字符
	 * @param $from 原始编码
	 * @param $to 转换的编码
	 */
	public static function stringCoding($string='',$from='gbk',$to='UTF-8')
	{
		if(isset($string)){
			if(function_exists('mb_convert_encoding')){
				$string = str_replace("\xC2\xA0", '&nbsp;', $string);
				$string = mb_convert_encoding($string,$to,$from);
			}
			else{
				$string = iconv($string, $to, $from);
			}
		}
		return $string;
	}






	//得到产品与服务链接地址
	//整理：张伟杰
	//@date: 2014.10.16
	//旧版商铺使用
	public static function getKeyWordUrl($str,$type = '',$isShow=true,$excludes='')
	{
		if(!empty($str) && preg_match("/[ais]/",$str) && strpos($str,':') && strpos($str,';') && strpos($str,'{'))
		$str = preg_replace("/[ais;:\d\{\}]+/",',',$str);
		$str = strip_tags($str);
		$clear = array('|',';','/','／','｜','_','＿','-','－','\\','＼','，','、','；','　','.','．','<','＜','＞','>','［','］','[',']','{','}','｛','｝','?','？','：',':','＇','\'','＂','"','(',')','（','）',',',' ','。');

		// 排除指定的符号
		if (!empty($excludes))
		{
			if(!array($excludes)) $excludes = explode(',',$excludes);
			$clear = array_diff($clear,$excludes);
		}
		$n = strlen($str);
		$reStr = '';
		for($i = 0;$i<$n;$i++)
		{
			$b=self::cnSubStr($str,1,'',$i);
			if(strlen($b) > 1)
			{
				$i++;
			}
			if(in_array($b,$clear))
			{
				$reStr = trim($reStr);
				if(!empty($reStr))
				{
					$arrPN[] = $reStr;
					$reStr = '';
				}
			}
			else
			{
				$reStr .= $b;
			}
		}
		if(is_array($arrPN))
		{
			if(!empty($reStr))
			{
				$arrPN[] = $reStr;
				$reStr = '';
			}
			if(!$isShow) return $arrPN;
			$i = 0;
			foreach($arrPN as $v)
			{
				$reStr .= '<a href="http://www.net114.com/s'.(empty($type)?'':$type.':').urlencode($v).'.html" target="_blank" title="'.$v.'">'.$v.'</a>'.set_place_food_keyword_match($type,$v).'&nbsp;';
				if(++$i == 5) break;
			}
		}
		else
		{
			if(!$isShow) return array($reStr);
			$str = $reStr;
			$reStr = '';
			$reStr .= '<a href="http://www.net114.com/s'.(empty($type)?'':$type.':').urlencode($str).'.html" target="_blank" title="'.$str.'">'.$str.'</a>&nbsp;';
		}
		return $reStr;
	}





	/*
	*函数作用：得到用户IP地址
	*函数名称：strFunIP
	*返 回 值：str
	*Author: 张伟杰
	*创建日期: 2014.10.22
	*/
	public static function strFunIP()
	{
		if($_SERVER["HTTP_X_FORWARDED_FOR"])
		$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
		elseif ($_SERVER["HTTP_CLIENT_IP"])
		$ip = $_SERVER["HTTP_CLIENT_IP"];
		elseif ($_SERVER["REMOTE_ADDR"])
		$ip = $_SERVER["REMOTE_ADDR"];
		elseif (getenv("HTTP_X_FORWARDED_FOR"))
		$ip = getenv("HTTP_X_FORWARDED_FOR");
		elseif (getenv("HTTP_CLIENT_IP"))
		$ip = getenv("HTTP_CLIENT_IP");
		elseif (getenv("REMOTE_ADDR"))
		$ip = getenv("REMOTE_ADDR");
		else
		$ip = "Unknown";
		return $ip;
	}




	/**
	 * 获取产品详细页地址
	 * @param int $id 产品ID
	 * @param string $username 用户名
	 * @return string
	 * @author 张伟杰
	 */
	public static function get_product_detail_url($id,$username='')
	{
		if(!is_numeric($id))
		return;
		if($id < 1)
		return;
		if(!$username)
		{
			$username = 'detail';
		}
		//大于 1016524588 随机取模
		if ($id > 1016524588)
		{
			if($id % 2 == 0  && $username != 'detail')
			{
				$url = "http://{$username}.net114.com/product/{$id}.html";
			}else
			{
				$url = "http://detail.net114.com/chanpin/{$id}.html";
			}
		}
		else if(($id > 3350156 && $id < 3595321) || ($id > 1000000000 && $id < 1016524588) )
		{
			if($username != 'detail') $url = "http://{$username}.net114.com/product/{$id}.html";
			else $url = "http://detail.net114.com/chanpin/{$id}.html";
		}
		else
		{
			if($id % 2 == 0 && $username != 'detail')
			{
				$url = "http://{$username}.net114.com/product/{$id}.html";
			}else
			{
				$url = "http://detail.net114.com/chanpin/{$id}.html";
			}
		}
		return $url;
	}



	/**
	 * 获取企业站地址
	 *
	 * @param int $id 会员ID
	 * @param string $username 用户名
	 * @return string
	 */
	public static function get_corp_detail_url($id,$username='')
	{
		if(!is_numeric($id))
		return;
		if($id < 1)
		return;
		if($username)
		$url = "{$username}.net114.com/";
		elseif(($id > 229669530 && $id < 700000000) || $id >= 766939486)
		$url = "detail.net114.com/gongsi/{$id}.html";
		else
		$url = "detail.net114.com/gongsi/{$id}.html";
		return 'http://'.$url;
	}


	/**
	 * 输出类公共函数注释
	 * @param $className 类名
	 */
	public function  outputClassNotes($className='')
	{
		if(!empty($className)){
			$arrMethods = get_class_methods($className);//获取类所有函数
			if(is_array($arrMethods)){
				$arrMatchParam = array('@param','@return','@deprecated','@author');
				$arrMatchParamDoc = array('<br/><span style="color:#060;">参数：</span><br/>',
				'<br/><span style="color:#060;">返回类型：</span><br/>',
				'<br/><span style="color:#060;">函数描述：</span><br/>',
				'<br/><span style="color:#060;">作者：</span><br/>'
				);
				echo '<h2>类名：'.$className.'</h2>';
				foreach ($arrMethods as $k=>$v){
					if(!empty($v)){
						$method = new ReflectionMethod($className,$v);
						if($method->isPublic()){
							//过滤析构函数和构造函数
							if(!in_array($v,array('__construct','__destruct'))){
								$strDoc = $method->getDocComment();
								$arrParams = $method->getParameters();//获取参数名
								$strParamName = '(';
								foreach ($arrParams as $kk=>$vv){
									$strParamName .= $vv->name.',';
								}
								$strParamName = trim($strParamName,',').')';
								$strFumName =  $v.' '.$strParamName;
								$strDoc = str_replace(array('*','/'),'',$strDoc);
								$strDoc = str_replace($arrMatchParam,$arrMatchParamDoc,$strDoc);
								echo '<p><span style="color:#060;">函数名：</span>'.$strFumName.'</p>';
								echo $strDoc;
								echo '<hr/>';
							}
						}
					}
				}
			}
		}
	}

	/**
	 * 获取到网站域名
	 * @param $type 类型 对应 theme.inc.php 配置常量WEB_DOMIAN_URL顺序
	 */
	public static function get_domain_url($type='')
	{
		if(!empty($type)){
			$strDomainUrl = WEB_DOMIAN_URL;
			if(!empty($strDomainUrl)){
				$arrDomainUrl = unserialize($strDomainUrl);
				return $arrDomainUrl[$type-1];
			}
		}
	}



	/**
		 * 产品属性处理
		 * 整理：张伟杰
		 * @param array $arrAttr
		 */
	public  static function productAttrHandle($arrAttr = null)
	{
		if(!empty($arrAttr))
		{
			$arrAttr = preg_replace("|[^}]+{::::}|U",'',$arrAttr);
			if(!empty($arrAttr)){
				$arrAttr = explode('::}',$arrAttr);
				if(count($arrAttr)%2==1){
					array_pop($arrAttr);
				}
				if(is_array($arrAttr) && count($arrAttr) > 0)
				{
					$arrSortArrData = array();
					$intSortNum = 0;
					foreach ($arrAttr as $kpa=>$vpa)
					{
						if(!empty($vpa))
						{
							$arrProductLeftAttr = explode('{::',$vpa);
							if(!in_array($arrProductLeftAttr[0],array('品牌','产地'))){
								$arrSortArrData[$intSortNum]['KEY']=$arrProductLeftAttr[0];
								$arrSortArrData[$intSortNum]['VALUE']=$arrProductLeftAttr[1];
								$intSortNum=$intSortNum+1;
							}
						}
					}
				}
			}
			return $arrSortArrData;
		}
	}

	/**
	 * 获取信息审核id
	 * @param string $business  对应业务表名
	 * @author dora
	 * @return int|bool
	 */
	public  static function get_msg_type($business='')
	{
		if(!empty($business)){
			$msgTypeList = unserialize(MSG_TYPE_LIST);
			if(is_array($msgTypeList)){
				return !empty($msgTypeList[$business][0])?$msgTypeList[$business][0]:false;
			}
		}else {
			return false;
		}
	}

	/**
	 * 获取信息审核原因名称
	 * @param int $num  对应业务表名
	 * @author dora
	 * @return string|bool
	 */
	public  static function get_msg_type_name($num='')
	{
		if(!empty($num)){
			$msgTypeList = unserialize(MSG_TYPE_LIST);
			if(is_array($msgTypeList)){
				$business = '';
				foreach ($msgTypeList as $k=>$v){
					if($v[0] == $num){
						$business = $k;
						break;
					}
				}
				return $business?$business:false;
			}
		}else {
			return false;
		}
	}


	/**
	 * 获取信息类型字段
	 * @param string $business  对应业务表名
	 * @author hxch
	 * @return string
	 */
	public  static function get_msg_type_fields($business='')
	{
		if(!empty($business)){
			$msgTypeList = unserialize(CHECK_BUSINESS_FIELDS);
			if(is_array($msgTypeList)){
				return !empty($msgTypeList[$business])?$msgTypeList[$business]:'';
			}
		}else {
			return '';
		}
	}


	/**
	 * 获取到前台的频道名
	 * @param int $num  对应业务表名
	 * @author dora
	 * @return string|bool
	 */
	public  static function get_channel_name($num='')
	{
		if(!empty($num)){
			$msgTypeList = unserialize(MSG_TYPE_LIST);
			if(is_array($msgTypeList)){
				$channel = '';
				foreach ($msgTypeList as $k=>$v){
					if($v[0] == $num){
						$channel = $v[1];
					}
				}
				return $channel?$channel:false;
			}
		}else {
			return false;
		}
	}

	/**
	 * 获取热门关键字
	 * @param msgType 信息类别(0=默认全部，对应/system/config/theme.inc.php全局变量MSG_TYPE_LIST)
	 * @param $limit 条数
	 * @author  邝达峰
	 * @return string
	 */
	public static function get_hot_search_key($msgType = 1 ,$limit = 8)
	{
		$arrSearchName = array(
		'1'=>'product',
		'2'=>'serve',
		'3'=>'corp',
		'4'=>'business',
		'5'=>'baike',
		'6'=>'news',
		'7'=>'demand',
		'8'=>'jobs',
		'9'=>'activity',
		'10'=>'tushuo',
		'15'=>'supplier',
		);
		$arrSearchModule = array(
		'product'=>'1',
		'service'=>'2',
		'company'=>'3',
		'business'=>'4',
		'baike'=>'5',
		'news'=>'6',
		'demand'=>'7',
		'jobs'=>'8',
		'activity'=>'9',
		'tushuo'=>'10',
		'supplier'=>'15',
		);
		if(is_string($msgType))
		{
			$msgType = $arrSearchModule[$msgType] ;
		}
		if(!empty($msgType))
		{
			$sql = "select id,kw,url,msgType,isTop from keywords_hot where  msgType in (0,".intval($msgType).") and checkState=2 order by isTop desc, dateline desc limit ".$limit;
			$arrData = DB::select($sql);
			if(is_array($arrData) && count($arrData) > 0)
			{
				foreach ($arrData as $k=>$v)
				{
					if(!empty($v['URL'])){
						$arrData[$k]['SHOWURL'] = $v['URL'];
					}else
					{
						$strSearchName = $arrSearchName[$v['MSGTYPE']];
						$strSearchName = $strSearchName?$strSearchName:'product';
						$arrData[$k]['SHOWURL'] = 'http://search.net114.com/'.$strSearchName.'-sw-'.urlencode($v['KW']).'.html';
					}
				}
			}
		}
		return $arrData;
	}


	/**
     * 根据信息类型id及信息id 生成信息详情页URL
     * @param int $msgType 信息类型id或者信息类型名称如company
     * @param int $id 信息id
     * @param str $username 用户名
     * @return string|bool $url 信息详情页URL
     */
	public static function createDetailUrlById($msgType='', $id='',$username='')
	{
		if($username) {
			$url =  'http://'.$username.'.net114.com';
		}elseif(!empty($msgType) && !empty($id)) {
			
			$id = intval($id);
			$typeList = unserialize(MSG_TYPE_LIST);

			$url_path = '';
			if(is_string($msgType) && $typeList[$msgType]){
				
				$url_path = $typeList[$msgType][2]?$typeList[$msgType][2]:'';
			}else{
				$msgType = intval($msgType);
				if(is_array($typeList)){
					foreach ($typeList as $v) {
						if($v[0] == $msgType){
							$url_path = $v[2];
							break;
						}
					}
				}
			}

			if($url_path){
				$url =  self::get_domain_url(2) . '/'.$url_path.'/' . $id . '.html';
			}

		}
		return $url?$url:false;
	}

	/**
     * 根据信息类型id 获取信息名（如：产品）
     * @param $msgType 信息类型id
     * @return string|bool $msgName 信息名
     *
     */
	public static function getMsgNameById($msgType)
	{
		if(!empty($msgType)){
			$msgType = intval($msgType);
			$msgTypeList = unserialize(MSG_TYPE_LIST);
			if(is_array($msgTypeList)){
				$msgName = '';
				foreach ($msgTypeList as $k=>$v){
					if($v[0] == $msgType){
						$msgName = $v[1];
						break;
					}
				}
			}
		}

		return $msgName ? $msgName : false;
	}


	/**
	 * 大全省份
	 * @param string $c 省份缩写(该省份将被过滤，表示获取其他省份)
	 * @param int $filter 过滤级别：0保留“省|市”，1完全过滤
	 * @return array
	 */
	public static function get_daquan_province($c='',$filter=0)
	{

		include(SYSTEM_PATH.'libs/data/province.lib.php');
		$pattern = $filter ? "/省|市|特别行政区|自治区|壮族|回族|维吾尔/" : "/特别行政区|自治区|壮族|回族|维吾尔/";

		if($c && $code = $Areapy['SEC_CITY_ABBR'][$c])
		{
			if($tmp = array_search(substr($code,0,6),$Areapy['SEC_PROVINCE_ABBR']))
			$c = $tmp;
		}

		$data = array();
		foreach($Province as $k=>$v)
		{
			if(in_array($k,$Region['105'][1]))
			$k .= '101';
			$key = array_search($k,$Areapy['SEC_PROVINCE_ABBR']);
			if(!$key)
			$key = array_search($k,$Areapy['SEC_CITY_ABBR']);
			if($key != $c)
			$data[$key] = preg_replace($pattern,'',$v);
		}
		return $data;
	}




	/**
	*@param 转价格转换为大写
	*@param $rmb 价格数值
	*@atuhor 张伟杰
	*/
	public static function cnprice($rmb){
		$rmb=str_replace(",","",$rmb); //格式化 1,000,000的金额

		if(!preg_match("/^[0-9.]/",$rmb)) return " ";//如果金额不正确则返回空值
		$arr1 = array('零','壹','贰','叁','肆','伍','陆','柒','捌','玖');
		$arr2 = array('拾','佰','仟');
		$arr=explode(".",$rmb);
		$rmb_len=strlen($arr[0]); //整数部分
		$j=0;
		for ($i=0;$i<$rmb_len;$i++){
			$bit=$arr[0][$rmb_len-$i-1];
			$cn=$arr1[$bit];
			$unit=$arr2[$j];
			if ($i==0) {
				$re=$cn;
			}
			elseif ($i==4){
				$re=$cn."万".$re;
				$j=0;
			}
			elseif ($i==8) {
				$re=$cn."亿".$re;
				$j=0;
			}
			else{
				$j++;
				$re=$bit==0?"零".$re:$cn.$unit.$re;
			}
		}
		if ($arr[1]){
			$arr[1][0]==0?$re=$re."元零":$re=$re."元".$arr1[$arr[1][0]]."角"; //角
			$arr[1][1]==0?$re=$re."零分":$re=$re.$arr1[$arr[1][1]]."分";      //分 www~phperz~com
		}
		//echo $re."<br>";
		$re=preg_replace(array("/(零)+$/","/(零)+/","/零万/","/零亿/"),array("","零","万","亿"),$re); //替换一些数据
		$arr[1]?$re:$re.="元整";
		return $re;
	}

	/**
	*获取公共头部信息
	*@atuhor dora
	*/
	public static function getPubTopHtml($uid){
		if(!empty($uid))
		{
			#登录处理
			$sessionObj = new  Session();
			$uid = $sessionObj->getSession('uid');
			$uname = $sessionObj->getSession('uname');
			$utype = $sessionObj->getSession('utype');
			$uid = $uid?$uid:$_COOKIE['uid'];
			$uname = $uname?$uname:$_COOKIE['uname'];
			$userUrl = Func::get_domain_url(3);
			#获取到企业性质
			if(!empty($uid)){
				$strCorpWorkSql = "select workMode from company where id = ".$uid;
				$arrCorpWork = DB::select($strCorpWorkSql);
				if(!empty($arrCorpWork)){
					$strWorkMode = $arrCorpWork[0]['WORKMODE'];
				}
			}
			//区分服务商还是生产商
			if(in_array($strWorkMode,array(3,4)))
			{
				$strProductMenuName = '服务信息';
				$strProductMenuUrl = '/member/serve.html';

				$strProductSendMenuName = '发布服务';
				$strProductSendMenuUrl = '/member/serve_form.html';

			}else
			{
				$strProductMenuName = '产品信息';
				$strProductMenuUrl = '/member/product.html';

				$strProductSendMenuName = '发布产品';
				$strProductSendMenuUrl = '/member/product_form.html';
			}
			if(!empty($uid)){
				/**变量处理**/
				#企业类型下拉菜单
				$arrCorpMenu = array(
				array(
				array('title'=>'信息管理','url'=>$userUrl.'/member/'),
				array('title'=>$strProductMenuName,'url'=>$userUrl.$strProductMenuUrl),
				array('title'=>'求购信息','url'=>$userUrl.'/member/demand.html'),
				array('title'=>'招商信息','url'=>$userUrl.'/member/business.html'),
				array('title'=>'企业新闻','url'=>$userUrl.'/member/news.html'),
				array('title'=>'中国智造','url'=>$userUrl.'/member/made.html'),
				array('title'=>'分类信息','url'=>$userUrl.'/member/classify.html'),
				),
				array(
				array('title'=>'快捷发布','url'=>$userUrl.'/member/'),
				array('title'=>$strProductSendMenuName,'url'=>$userUrl.$strProductSendMenuUrl),
				array('title'=>'发布求购','url'=>$userUrl.'/member/demand_form.html'),
				array('title'=>'发布招商','url'=>$userUrl.'/member/business_form.html'),
				array('title'=>'发布新闻','url'=>$userUrl.'/member/news_form.html'),
				array('title'=>'发布智造','url'=>$userUrl.'/member/made.html'),
				array('title'=>'发布分类信息','url'=>$userUrl.'/member/classify-cmd-sort.html'),
				),
				array(
				array('title'=>'账号管理','url'=>$userUrl.'/member/'),
				array('title'=>'我的留言','url'=>$userUrl.'/member/message-cmd-outms.html'),
				array('title'=>'管理商铺','url'=>$userUrl.'/member/shop.html'),
				array('title'=>'优质供应商','url'=>$userUrl.'/member/quality.html'),
				array('title'=>'品牌实名','url'=>$userUrl.'/member/brand.html'),
				array('title'=>'我的收藏','url'=>$userUrl.'/member/personal_collect.html'),
				array('title'=>'我的粉丝','url'=>$userUrl.'/member/personal_fans.html'),
				),
				array(
				array('title'=>'企业需求','url'=>$userUrl.'/member/corp_demand.html'),
				array('title'=>'我要采购','url'=>$userUrl.'/member/corp_demand_purchase.html'),
				array('title'=>'服务外包','url'=>$userUrl.'/member/corp_demand_service.html'),
				array('title'=>'创意设计','url'=>$userUrl.'/member/corp_demand_design.html'),
				array('title'=>'工程合作','url'=>$userUrl.'/member/corp_demand_project.html'),
				array('title'=>'寻找并购','url'=>$userUrl.'/member/corp_demand_merger.html'),
				array('title'=>'&nbsp;更多&gt;&gt;','url'=>$userUrl.'/member/corp_demand.html'),
				)
				);
				#普通用户下拉菜单
				$arrPersonalMenu = array(
				array(
				array('title'=>'信息管理','url'=>$userUrl.'/member/'),
				array('title'=>'我的简历','url'=>$userUrl.'/member/personal_resume-cmd-resume.html'),
				array('title'=>'我的求职','url'=>$userUrl.'/member/personal_resume.html'),
				array('title'=>'我的梦想','url'=>$userUrl.'/member/personal_dream.html'),
				array('title'=>'咨询顾问','url'=>$userUrl.'/member/personal_counselor.html'),
				),
				array(
				array('title'=>'账号管理','url'=>$userUrl.'/member/'),
				array('title'=>'个人资料','url'=>$userUrl.'/member/personal.html'),
				array('title'=>'账号安全','url'=>$userUrl.'/member/accountSecure.html'),
				array('title'=>'我的积分','url'=>$userUrl.'/member/personal_integral.html'),
				array('title'=>'个人商铺','url'=>'http://me.net114.com/'.$uname.'/'),
				),
				array(
				array('title'=>'其他管理','url'=>$userUrl.'/member/'),
				array('title'=>'消息中心','url'=>$userUrl.'/member/personal_message.html'),
				array('title'=>'兴趣企业','url'=>$userUrl.'/member/personal_attention_corp.html'),
				)

				);
				#专业镇下拉菜单
				$arrTownshipsMenu = array(
				array(
				array('title'=>'信息管理','url'=>$userUrl.'/member/'),
				array('title'=>'招商政策','url'=>$userUrl.'/member/town_business_policy.html'),
				array('title'=>'招商联系','url'=>$userUrl.'/member/town_business_contact.html'),
				array('title'=>'相关批发市场','url'=>$userUrl.'/member/town_wholesale_market.html'),
				)
				);
				#批发市场下拉菜单
				$arrMarketMenu = array(
				array(
				array('title'=>'信息管理','url'=>$userUrl.'/member/'),
				array('title'=>'动态新闻','url'=>$userUrl.'/member/wholesale_market_news.html'),
				array('title'=>'招商信息','url'=>$userUrl.'/member/wholesale_market_business.html'),
				array('title'=>'市场通知','url'=>$userUrl.'/member/wholesale_market_inform.html'),
				)
				);
				#行业协会下拉菜单
				$arrAssociationMenu = array(
				array(
				array('title'=>'信息管理','url'=>$userUrl.'/member/'),
				array('title'=>'协会新闻','url'=>$userUrl.'/member/association_news.html'),
				array('title'=>'协会通知','url'=>$userUrl.'/member/association_inform.html'),
				)
				);
				#用户操作对象
				$userObj = new  userModel();
				#获取用户信息
				$arrLoginInfo = $userObj->getUserInfoById($uid);
				#处理用户信息
				$utype = $arrLoginInfo[0]['USERTYPE'];
				$corpname = $arrLoginInfo[0]['CORPNAME'];
				$uname = $arrLoginInfo[0]['USERNAMR'];
				/**头部处理**/
				$arrUserInfo = array();
				$arrUserInfo['uid'] = $uid;
				$arrUserInfo['uname'] = $uname;
				$arrUserInfo['utype'] = $utype;
				$arrUserInfo['corpname'] = $corpname?$corpname:$uname;
				#企业用户
				if(in_array($utype,array('0','1','6'))){
					$arrUserInfo['user_menu'] = $arrCorpMenu;
				}
				#个人用户
				else if($utype==2){
					$arrUserInfo['user_menu'] = $arrPersonalMenu;
				}
				#专业镇
				else if($utype==3){
					$arrUserInfo['user_menu'] = $arrTownshipsMenu;
				}
				#批发市场
				else if($utype==4){
					$arrUserInfo['user_menu'] = $arrMarketMenu;
				}
				#行业协会
				else if($utype==5){
					$arrUserInfo['user_menu'] = $arrAssociationMenu;
				}
			}
			//登录内容
			$strTopHtml = '<div id="top_login_status">';
			$strTopHtml .= '<b>您好，&nbsp;<a href="'.Func::get_domain_url(3).'/member/">'.$arrUserInfo['corpname'].'</a></b>';
			#用户菜单处理
			if(!empty($arrUserInfo['user_menu']))
			{
				$arrUserMenu = $arrUserInfo['user_menu'];
				$strTopMenuHtml = '<span id="top_login_content" ><div  style="width:auto;" class="top_drop_down" id="user_drop_down_content" style="display:none;">';
				foreach ($arrUserMenu as $k=>$v)
				{
					$arrZiMenu = $v;
					$intCount = 0;
					if($arrZiMenu)
					{
						$strTopMenuHtml.='<dl>';
						foreach ($arrZiMenu as $zk=>$zv)
						{
							if($intCount==0){
								$strTopMenuHtml.='<dt>';
							}else{
								$strTopMenuHtml.='<dd>';
							}
							$strTopMenuHtml.='<a rel="external nofollow" href="'.$zv['url'].'">'.$zv['title'].'</a>';
							if($intCount==0){
								$strTopMenuHtml.='</dt>';
							}else{
								$strTopMenuHtml.='</dd>';
							}
							$intCount+=1;
						}//end foreach
						$strTopMenuHtml.='</dl>';
					}


				}//end foreach
				$strTopMenuHtml .= '</div></span>';
			}
			$strTopHtml .= '<p class="top_down top_down_on" id="user_drop_down"><a href="http://users.net114.com/member/" >用户中心</a></p><p><a href="javascript:void(0);" id="logout">退出</a></p>';
			$strTopHtml .= '</div>';
			if($strTopMenuHtml)
			{
				$strTopHtml = $strTopHtml.$strTopMenuHtml;
			}
		}else
		{
			//$nowVisitUrl = urlencode("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
			$strTopHtml = '<a href="'.Func::get_domain_url(21).'/login.html>登录</a>|<a href="'.Func::get_domain_url(21).'/reg.html">注册</a>';
		}
		return  $strTopHtml;
	}

	/**
	 * 获取到省市编码
	 * @param  $arrCity
	 */
	public function get_province_city_code($arrCity = '')
	{
		if(!empty($arrCity))
		{
			include_once(SYSTEM_PATH.'include/province_city.lib.php');
			if(!empty($arrPubProvinceCity)){
				$arrCityCode = array();
				$AreaObj =  new AreaSet();
				if(is_string($arrCity))
				{
					$arrCity = array($arrCity);
				}
				foreach ($arrCity as $k=>$v){
					$strCity = str_replace(array('市','省','区','自治'),'',$v);
					$intCityCode = $arrPubProvinceCity[$strCity];
					if($intCityCode)
					{
						$strCityPy = $AreaObj->getpy($intCityCode);
						array_push($arrCityCode,array('code'=>$intCityCode,'name'=>$v,'py'=>$strCityPy));
					}
				}
			}
			return $arrCityCode?$arrCityCode:false;
		}

	}

	/**
	 * 计算中英文字符长度
	 * @param  $str 需要计算的长度
	 * @param  $charset 字符编码 默认是gb2312
	 */
	public function countCnLen($str,$charset='gb2312'){
		if($charset=='utf-8') {
			$str = iconv('utf-8','gb2312',$str);
		}
		$num = strlen($str);
		$cnNum = 0;
		for($i=0;$i<$num;$i++){
			$countCn = substr($str,$i,1);
			if(!is_numeric($countCn)){
				if(ord($countCn)>127){
					$cnNum++;
					$i++;
				}
			}
		}
		$enNum = $num-($cnNum*2);
		$number = $enNum+$cnNum;
		return ceil($number);
	}

	/**
	 * 检测来源网址
	 * 如：表单提交，需验证只能从指定的来源提交数据
	 *
	 * @param array $url 正确的来源路径
	 * @param int $type 比较类型，0完整比较，1截取$_SERVER['HTTP_REFERER']的部分内容比较
	 * @param int $index 跳转路径（$url的键值）
	 */
	public static function check_http_referer($url='',$type=0,$index=0){
		if(!$url)
		$url = $_SERVER['SCRIPT_URI'];

		if(!is_array($url))
		$url = array($url);

		$http_referer = preg_replace("/\?.*$/","",$_SERVER['HTTP_REFERER']);//处理来源地址


		if($type)
		{
			$i = 0;
			foreach($url as $v)
			{
				if(substr($http_referer,0,strlen($v)) == $v)
				{
					$i++;
					break;
				}
			}
			if(!$i)
			$backurl = $_SERVER['SCRIPT_URI'];
		}
		else
		{
			if(!in_array($http_referer,$url))
			$backurl = $url[$index];

		}

		if($backurl)
		{
			echo '<script type="text/javascript">alert("很抱歉，数据提交不成功，请返回重新提交！");location.href="'.$backurl.'";</script>';
			exit;
		}
	}
	/**
	 * 过滤非站内链接
	 * @param  $body 内容
	 * @param  $allow_urls 允许的超链接
	 * @return $body
	 */
	function replace_outside_Links($body,$allow_urls=array()){
		$host_rule = join('|',$allow_urls);
		$host_rule = preg_replace("#[\n\r]#","",$host_rule);
		$host_rule = str_replace(".","\\.",$host_rule);
		$host_rule = str_replace("/","\\/",$host_rule);
		$arr = "";
		preg_match_all("#<a([^>]*)>(.*)<\/a>#iU", $body, $arr);
		if(is_array($arr[0])){
			$rparr = array();
			$tgarr = array();
			foreach($arr[0] as $i=>$v){
				if($host_rule !='' && preg_match("#".$host_rule."#i",$arr[1][$i])){
					continue;
				}else{
					$rparr[] = $v;
					$tgarr[] = '';
				}
			}
			if(!empty($rparr)){
				$body = str_replace($rparr,$tgarr,$body);
			}
		}
		$arr = $rparr = $tgarr ='';
		return $body;

	}

	/**
      * 通过搜索引擎获取热门搜索关键字
      * @param $channel 频道
      * @param $keyword 关键字
      */
	public function get_hot_keyword_by_solr($channel, $keyword)
	{
		if(empty($channel) || empty($keyword)){
			return ;
		}
		$arrSearchName = array(
		'1'=>'product',
		'2'=>'serve',
		'3'=>'corp',
		'4'=>'business',
		'5'=>'baike',
		'6'=>'news',
		'7'=>'demand',
		'8'=>'jobs',
		'9'=>'activity',
		'10'=>'tushuo',
		'15'=>'supplier',
		);
		$arrSearchModule = array(
		'product'=>'1',
		'service'=>'2',
		'company'=>'3',
		'business'=>'4',
		'baike'=>'5',
		'news'=>'6',
		'demand'=>'7',
		'jobs'=>'8',
		'activity'=>'9',
		'tushuo'=>'10',
		'supplier'=>'15',
		);
		if(is_string($channel))
		{
			$msgType = $arrSearchModule[$channel == 'company' ? 'product' : $channel];
		}
		if(empty($msgType)){
			return ;
		}
		$business = 'stat_keyword_channel';
		$objSolr = new SolrApi();
		$objSolr->set_debug_mode(0);
		$keyword = $objSolr->filter_illegality_string($keyword);
		$objSolr->add_query($business,$keyword);
		$objSolr->set_return_fields('keyword');
		$objSolr->set_pager(1,6);
		$objSolr->set_boost_rule($business);
		$objSolr->set_filter_query('msgType:'.$msgType);
		$arrData = $objSolr->get_result();
		if(is_array($arrData) && count($arrData))
		{
			foreach ($arrData as $k=>$v){
				if($v['keyword']==$keyword){
					unset($arrData[$k]);
					continue;
				}
				$strSearchName = $arrSearchName[$arrSearchModule[$channel]];
				$strSearchName = $strSearchName?$strSearchName:'product';
				$arrData[$k]['view_url'] = 'http://search.net114.com/'.$strSearchName.'-sw-'.urlencode($v['keyword']).'.html';
			}

		}
		return $arrData;
	}

	/**
      * 通过关键词ID获取 热门关键词 ，相关关键词，分词列表
      * @param $channel 频道
      * @param $keyId 关键词ID
      */
	public function get_fenci_by_sql ($keyId='',$channel='')
	{
		$arrSearchName = array(
		'1'=>'product',
		'2'=>'serve',
		'3'=>'corp',
		'4'=>'business',
		'5'=>'baike',
		'6'=>'news',
		'7'=>'demand',
		'8'=>'jobs',
		'9'=>'activity',
		'10'=>'tushuo',
		'15'=>'supplier',
		);
		$arrSearchModule = array(
		'product'=>'1',
		'service'=>'2',
		'company'=>'3',
		'business'=>'4',
		'baike'=>'5',
		'news'=>'6',
		'demand'=>'7',
		'jobs'=>'8',
		'activity'=>'9',
		'tushuo'=>'10',
		'supplier'=>'15',
		);
		if(is_string($channel))
		{
			$msgType = $arrSearchModule[$channel == 'company' ? 'product' : $channel];
		}
		if(empty($keyId)){
			return null;
		}
		$arrData = DB::select('select word_seg_list,word_rel_list,word_hot_list from cronjob_word_segment where id ='.$keyId.' limit 1');
		if($arrData){
			$arrKeyData = array();
			$word_seg_list = $arrData[0]['WORD_SEG_LIST'];//分词列表
			$word_rel_list = $arrData[0]['WORD_REL_LIST'];//相关关键词
			$word_hot_list = $arrData[0]['WORD_HOT_LIST'];//热门关键词
			#分词列表处理
			if($word_seg_list){
				$arrSegVal = json_decode($word_seg_list);
				foreach ($arrSegVal as $ks=>$vs){
					$arrSegVal[$ks] = Func::stringCoding($vs,'utf-8','gbk');
				}
				$arrKeyData['WORD_SEG_LIST'] = $arrSegVal;
			}
			#相关关键词处理
			if($word_rel_list){
				$arrRelVal = json_decode($word_rel_list);
				foreach ($arrRelVal as $kr=>$vr){
					$relVal = Func::objectToArray($vr);
					$relVal['kw'] = Func::stringCoding($relVal['kw'],'utf-8','gbk');
					$arrRelVal[$kr] = $relVal;
				}
				$arrKeyData['WORD_REL_LIST'] = $arrRelVal;
			}
			#热门关键词处理
			if($word_hot_list){
				$arrHotVal = json_decode($word_hot_list);
				$arrHotValData = array();
				foreach ($arrHotVal as $kh=>$vh){
					$arrChannel = $vh;
					if($arrChannel){
						$arrChannelData = array();
						foreach ($arrChannel as $khc=>$vhc){
							$channelVal = Func::objectToArray($vhc);
							$channelVal['keyword'] = Func::stringCoding($channelVal['keyword'],'utf-8','gbk');
							$arrChannelData[$khc]['keyword'] = $channelVal['keyword'];
							$strSearchName = $arrSearchName[$arrSearchModule[$channel]];
							$strSearchName = $strSearchName?$strSearchName:'product';
							$arrChannelData[$khc]['view_url'] = 'http://search.net114.com/'.$strSearchName.'-sw-'.urlencode($channelVal['keyword']).'.html';
						}
					}
					$arrHotValData[$kh] = $arrChannelData;
				}
				$arrReturnHotVal = array();
				if($arrHotValData[$msgType]){
					$arrReturnHotVal = $arrHotValData[$msgType];
				}
				$arrKeyData['WORD_HOT_LIST'] = $arrReturnHotVal;
			}
		}
		return $arrKeyData;
	}

	/**
     * 设置加密
     * 简单对称加密算法之加密,base64二次加密
     * @param String $string 需要加密的字串
     * @param String $skey 加密EKY
     * @return String
    */
	public function set_encrypt($string = '', $skey = '')
	{
		if(!empty($string))
		{
			return Encrypt::base64_twice_encode($string,$skey);
		}
		return $string;
	}

	/**
     * 获取解密
     * 简单对称加密算法之解密,base64二次解密
     * @param String $string 需要解密的字串
     * @param String $skey 解密KEY
     * @return String
    */
	public function get_encrypt($string = '', $skey = '')
	{
		if(!empty($string))
		{
			return Encrypt::base64_twice_decode($string,$skey);
		}
		return $string;
	}



	/**
	 * 视频文件地址处理 文件路径集群处理
	 * @author 邝达峰
     * @param array $url 
     */
	public static function videoUrlHandle($url='')
	{
		if(!empty($url)){
			#文件路径处理
			$file_pathes = explode('|',USER_THEME_FILE_URL);
			#过滤处理域名
			foreach ($file_pathes as $k){
				$url = str_replace($k,'',$url);
			}
			#读取文件配置
			$arrFileConfig = Config::get('file');
			#文件路径处理
			$arrFilePath = pathinfo($url);
			$fileName = $arrFilePath['basename'];
			$arrconfig = $arrFileConfig['FILE_DOMAIN_CFG']['FLV_CONFIG'];
			$sttDomain = $arrconfig['default']['domain'][0];
			$arrStr = explode('.',$fileName);
			$strPrefix = $arrStr[0];
			$arrPrefix = explode('_',$strPrefix);
			if(!empty($arrPrefix) && count($arrPrefix) == 2){
				$strPrefix = substr($arrPrefix[0],0,1);
				if(is_array($arrconfig[$strPrefix])){
					if(in_array($arrPrefix[0],$arrconfig[$strPrefix]['prefix'])){
						$sttDomain= $arrconfig[$strPrefix]['domain'][0];
					}
				}
			}
		}
		$url = $sttDomain.str_replace($sttDomain,'',$url);
		return $url;
	}



	/**
	 * 获取地区信息
	 * @param $areaid 地区ID
	 * @param $unit  为true时带单位（如省，市，区），否则不带
	 * return array('province'=>'广东','city'=>'广州','area'=>'天河区');
	 */

	public static function get_area_info($areaid,$unit){
		if(empty($areaid)){
			return false;
		}
		include(SYSTEM_LIB_PATH.'data/province.lib.php');
		$len = strlen($areaid);
		$arrArea = array('province'=>'','city'=>'','area'=>'');
		$arrReplace = array('市','区','县');
		switch ($len){
			case 6:
				if($unit){
					$arrArea['province'] = $Province2[substr($areaid,0,6)];
				}else{
					$arrArea['province'] = $Province[substr($areaid,0,6)];
				}

				break;
			case 9:
				if($unit){
					$arrArea['province'] = $Province2[substr($areaid,0,6)];
				}else{
					$arrArea['province'] = $Province[substr($areaid,0,6)];
				}


				$arrArea['city'] = $City[substr($areaid,0,6)][substr($areaid,0,9)];
				break;
			case 12:
				if($unit){
					$arrArea['province'] = $Province2[substr($areaid,0,6)];
				}else{
					$arrArea['province'] = $Province[substr($areaid,0,6)];
				}
				$arrArea['city'] = $City[substr($areaid,0,6)][substr($areaid,0,9)];
				$arrArea['area'] = $County[substr($areaid,0,9)][substr($areaid,0,12)];
				if(!$unit){
					$arrArea['city'] = str_replace($arrReplace,'',$arrArea['city']);
					$arrArea['area'] = str_replace($arrReplace,'',$arrArea['area']);
				}

				break;

		}
		return $arrArea;
	}
	
	public static function getFContent($url)
	{
		$timeout=5;//等待5秒
		//$old_timeout=ini_get('default_socket_timeout');
		//ini_set('default_socket_timeout',$timeout);

		$opts = array(
		'http'=>array(
		'timeout'=>$timeout,
		)
		);

		$context = stream_context_create($opts);
		$content = @file_get_contents($url,false,$context);
		//ini_set('default_socket_timeout',$old_timeout);
		return $content;
	}
	
	
	/*数组排序
	* $ArrayData排序的KEY名
	*/
	function sysSortArray($ArrayData,$KeyName1,$SortOrder1 = "SORT_ASC",$SortType1 = "SORT_REGULAR")
	{
		if(!is_array($ArrayData))
		{
			return $ArrayData;
		}

		// Get args number.
		$ArgCount = func_num_args();

		// Get keys to sort by and put them to SortRule array.
		for($I = 1;$I < $ArgCount;$I ++)
		{
			$Arg = func_get_arg($I);
			if(!eregi("SORT",$Arg))
			{
				$KeyNameList[] = $Arg;
				$SortRule[]    = '$'.$Arg;
			}
			else
			{
				$SortRule[]    = $Arg;
			}
		}

		// Get the values according to the keys and put them to array.
		foreach($ArrayData AS $Key => $Info)
		{
			foreach($KeyNameList AS $KeyName)
			{
				${$KeyName}[$Key] = $Info[$KeyName];
			}
		}

		// Create the eval string and eval it.
		if(is_array($SortRule) && count($SortRule) > 0)
		{
			/**邝达峰修改**/
			array_multisort($NUMS,SORT_DESC,$ArrayData);
			//$EvalString = 'array_multisort('.join(",",$SortRule).',$ArrayData);';
			//eval ($EvalString);
		}
		return $ArrayData;
	}
	
	
	/*
	**检查是否黑名单用户 dora 添加
	*/
	function checkUserBlacklist($shopid='')
	{
		if(!empty($shopid))
		{
			$sql = 'select id,shopid from users_blacklist where shopid = '.intval($shopid);
			$arrData = DB::G('insert')->select($sql);
			if(is_array($arrData) && count($arrData) > 0)
			{
				header("HTTP/1.1 301 Moved Permanently");
				header('Location:http://www.net114.com/userblack-uid-'.$arrData[0]['SHOPID'].'.html');
				exit();
			}
		}
	}
	
	/*
	**过滤非法关键字 dora 添加
	*/
	public static function filterIllegalityKey($content = '')
	{
		if(!empty($content))
		{
			include(SYSTEM_PATH.'include/data/key_shield.inc.php');
			if(is_array($publicKeyShield) && count($publicKeyShield) > 0)
			{
				foreach ($publicKeyShield as $k=>$v)
				{
					$content = str_replace($v,'',$content);
				}
			}
			return  $content;
		}
	}
	
	
	
	/**
	 * 获取到城市拼音简写
	 * @param string $city
	 * @return array
	 */
	public static function get_city_py($city='')
	{
		if(empty($city)){
			return false;
		}
		include(SYSTEM_PATH.'libs/data/province.lib.php');
		$arrCityPy = $Areapy['SEC_CITY_ABBR'];
		$strCityPy = $city;
		if($arrCityPy){
			foreach ($arrCityPy as $k=>$v){
				if($city==$v){
					$strCityPy = $k;
				}
			}
		}
		return $strCityPy;
	}



}

?>
